Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Angular nested property binding inside [innerHTML]

I'm dynamically adding come content to page, let's consider following example:

const dataArray = [
  {id: 1, innerHtml: `Some plain Txt`},
  {id: 2, innerHtml: `Some plain Txt`},
  {id: 3, innerHtml: `Some plain Txt`},
]

And inside component template:

<div *ngFor="let e of dataArray">
 <p [innerHTML]="e.innerHtml"></p>
</div>

All works fine, until I need some nested property binding, like following:

...
  {id: 2, innerHtml = `Some plain Txt with anchor: <a [href]="'most/plain/url/link'" >Link</a>`},
...

I'm passing values via security bypass pipe:

@Pipe({name: 'safeHtml'})
export class Safe implements PipeTransform {
    constructor(private sanitizer: DomSanitizer){}

    transform(style) {
        return this.sanitizer.bypassSecurityTrustHtml(style);
    }
}

But always resulting with: empty href property of a tag when not using security bypass pipe or with non-interpolated, copy-pasted version of it (e.g. <a [href]="'non/interpolated'"></a>)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

<a> tag is native element, so don't pass values as property bindings. Instead of [href]="'most/plain/url/link'" just do href='most/plain/url/link'.

innerHtml: `Some plain Txt with anchor: <a href='most/plain/url/link' >Link</a>`

Working example

about 4 years ago · Juan Pablo Isaza Report

0

Don’t use href as angular input attribute since Angular is not going to parse it. Please use href directly like href=‘/url’

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!